package com.elinshaw;

import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.generated.StormTopology;
import org.apache.storm.topology.TopologyBuilder;

/**
 * 所有的spout bolt组成一个topology
 *
 * @author Administrator
 */
public class TopologyLocal {

    public static void main(String[] args) throws InterruptedException {
        //storm环境参数对象
        Config config = new Config();
        config.setDebug(false);
        //用户绑定各组件间的上下游关系
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("number_spout", new NumberSpout());
        builder.setBolt("first_bolt", new FirstBolt()).shuffleGrouping("number_spout");
        builder.setBolt("time_bolt", new TimeBolt()).shuffleGrouping("first_bolt");
        builder.setBolt("print_bolt", new PrintBolt()).shuffleGrouping("time_bolt");
        //生成一个Job任务
        StormTopology stormTopology = builder.createTopology();
        //本地模式提交-创建本地测试对象
        LocalCluster cluster = new LocalCluster();
        //提交拓扑运行
        cluster.submitTopology("DemoTopologyLocal", config, stormTopology);
       /* TimeUnit.SECONDS.sleep(30);
        cluster.killTopology("myTopologyLocal");
        cluster.shutdown();*/
    }


}
